<?php
class Search extends Controller {
	function Search() {
		parent::Controller();
		$this->load->helper("url");
		$this->data["base"] = $this->config->item('base_url');
		$this->load->model('Searchmodel','',TRUE);
		
		$this->load->database();	
                session_start();
	}
	function index() {
		if((isset($_SESSION['admin']))||(isset($_SESSION['intern_audit']))||(isset($_SESSION['second_consult']))||(isset($_SESSION['dept_pic']))) {
			$this->show_search();
		} else {
			redirect('main');
		}

	}
	function show_search() {
		//set template
		$this->load->vars($this->data);
		$this->load->view('layout/head');
		$this->load->view('layout/body');
		$this->load->view('layout/search');
		$this->load->view('search/search_data');
		$this->load->view('layout/foot');
	}
	function show_search_by() {
		$this->data['title'] ='Advanced Search';
		$by2 = $this->input->post('order');
		$bys =$this->input->post('cari');
		if(isset($_POST['advanced'])) {
		if((($by2) != "") and (isset($by2) == "TickedID") and (($by2) != "DateRange") and (($by2) != "Severity") and (($by2) != "Comments") and (($by2) != "Product") and (($by2) != "Title")) {
			$ticket = $this->input->post('cari');
			//set template table untuk efek selang-sling tiap bariS
			$tmpl = array('table_open' =>'<table border="0" cellpadding="0" cellspacing="0" width="880" id="table" class="sortable">', 'heading_row_start'   => '<thead><tr>',
                    'heading_row_end'     => '</tr></thead>',
                    'heading_cell_start'  => '<th>',
                    'heading_cell_end'    => '</th>','row_alt_start' =>'<tr class="tb-jd">','row_alt_end' =>'</tr>');
			$this->table->set_template($tmpl);
			$this->table->set_empty("&nbsp;");
			$this->table->set_heading('No','<h3>ticket_id</h3>','<h3>title</h3>','<h3>Open Date</h3>','<h3>Target Date</h3>','<h3>Close Date</h3>',
			'<h3>status</h3>','<h3>Severity Level</h3>','<h3>prod</h3>','<h3>dept</h3>','<h3>Action</h3>');

			$ac = $this->Searchmodel->search_ticket($ticket);
			$i =0;
			foreach($ac->result() as $ac1) {
				$this->table->add_row(++$i,anchor('search/search/search_alls/'.$ac1->ticket_id,$ac1->ticket_id),$ac1->title,$ac1->open_datetime,$ac1->target_date,$ac1->close_date,$ac1->status,$ac1->severity_level,$ac1->product,$ac1->dept_name,anchor('createticket/mngticket/update_process/'.$ac1->ticket_id,'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;',array('class'=>'update')).''.
				anchor('createticket/mngticket/download_ticket/'.$ac1->ticket_id,'download',array('class'=>'download')));
			}
			
			
		}else if( (($by2) == "DateRange") and (($by2) != "Severity") and (($by2) != "Comments") and (($by2) != "Product") and (($by2) != "Title")) {
			$date = $this->input->post('cari');
			//set template table untuk efek selang-sling tiap bariS
			$tmpl = array('table_open' =>'<table border="0" cellpadding="0" cellspacing="0" width="880" id="table" class="sortable">','row_alt_start' =>'<tr class="tb-jd">', 'heading_row_start'   => '<thead><tr>',
                    'heading_row_end'     => '</tr></thead>',
                    'heading_cell_start'  => '<th>',
                    'heading_cell_end'    => '</th>','row_alt_end' =>'</tr>');
			$this->table->set_template($tmpl);
			$this->table->set_empty("&nbsp;");
			$this->table->set_heading('No','<h3>ticket_id</h3>','<h3>title</h3>','<h3>Open Date</h3>','<h3>Target Date</h3>','<h3>Close Date</h3>',
			'<h3>status</h3>','<h3>Severity_Level</h3>','<h3>product</h3>','<h3>Action</h3>');

			$acd = $this->Searchmodel->search_dateRange($date);
			$i =0;
			foreach($acd->result() as $ac12) {
				$this->table->add_row(++$i,anchor('search/search/search_alls/'.$ac12->ticket_id,$ac12->ticket_id),$ac12->title,$ac12->open_datetime,$ac12->target_date,$ac12->close_date,$ac12->status,$ac12->severity_level,$ac12->product,anchor('createticket/mngticket/update_process/'.$ac12->ticket_id,'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;',array('class'=>'update')).''.
				anchor('createticket/mngticket/download_ticket/'.$ac12->ticket_id,'download',array('class'=>'download')));
			}
			
			
		}else if((($by2) == "Severity") and (($by2) != "Comments") and (($by2) != "Product") and (($by2) != "Title")){
		
			$severity = $this->input->post('cari');
			//set template table untuk efek selang-sling tiap bariS
			$tmpl = array('table_open' =>'<table border="0" cellpadding="0" cellspacing="0" width="880" id="table" class="sortable">', 'heading_row_start'   => '<thead><tr>',
                    'heading_row_end'     => '</tr></thead>',
                    'heading_cell_start'  => '<th>',
                    'heading_cell_end'    => '</th>','row_alt_start' =>'<tr class="tb-jd">','row_alt_end' =>'</tr>');
			$this->table->set_template($tmpl);
			$this->table->set_empty("&nbsp;");
			$this->table->set_heading('No','<h3>ticket_id</h3>','<h3>title</h3>','<h3>Open Date</h3>','<h3>Target Date</h3>','<h3>Close Date</h3>',
			'<h3>status</h3>','<h3>Severity_Level</h3>','<h3>product</h3>','<h3>Action</h3>');

			$acd = $this->Searchmodel->search_severity($severity);
			$i =0;
			foreach($acd->result() as $ac12) {
				$this->table->add_row(++$i,anchor('search/search/search_alls/'.$ac12->ticket_id,$ac12->ticket_id),$ac12->title,$ac12->open_datetime,$ac12->target_date,$ac12->close_date,$ac12->status,$ac12->level_o_impact,$ac12->prob_o_impact,$ac12->severity_level,$ac12->product,anchor('createticket/mngticket/update_process/'.$ac12->ticket_id,'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;',array('class'=>'update')).''.
				anchor('createticket/mngticket/download_ticket/'.$ac12->ticket_id,'download',array('class'=>'download')));
			}
			
		}else if((($by2) == "Comments") and (($by2) != "Product") and (($by2) != "Title")) {
			
			$comments = $this->input->post('cari');
			//set template table untuk efek selang-sling tiap bariS
			$tmpl = array('table_open' =>'<table border="0" cellpadding="0" cellspacing="0" width="880" id="table" class="sortable">', 'heading_row_start'   => '<thead><tr>',
                    'heading_row_end'     => '</tr></thead>',
                    'heading_cell_start'  => '<th>',
                    'heading_cell_end'    => '</th>','row_alt_start' =>'<tr class="tb-jd">','row_alt_end' =>'</tr>');
			$this->table->set_template($tmpl);
			$this->table->set_empty("&nbsp;");
			$this->table->set_heading('No','<h3>ticket_id</h3>','<h3>title</h3>','<h3>Open Date</h3>','<h3>Target Date</h3>','<h3>Close Date</h3>',
			'<h3>status</h3>','<h3>Severity_Level</h3>','<h3>Comments</h3>','<h3>Action</h3>');

			$acd = $this->Searchmodel->search_comments($comments);
			$i =0;
			foreach($acd->result() as $ac12) {
				$this->table->add_row(++$i,anchor('search/search/search_alls/'.$ac12->ticket_id,$ac12->ticket_id),$ac12->title,$ac12->open_datetime,$ac12->target_date,$ac12->close_date,$ac12->status,$ac12->severity_level,$ac12->comments,anchor('createticket/mngticket/update_process/'.$ac12->ticket_id,'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;',array('class'=>'update')).''.
				anchor('createticket/mngticket/download_ticket/'.$ac12->ticket_id,'download',array('class'=>'download')));
			}
			
		}else if((($by2) == "Product") and (($by2) != "Title")) {
			$product = $this->input->post('cari');
			//set template table untuk efek selang-sling tiap bariS
			$tmpl = array('table_open' =>'<table border="0" cellpadding="0" cellspacing="0" width="880" id="table" class="sortable">', 'heading_row_start'   => '<thead><tr>',
                    'heading_row_end'     => '</tr></thead>',
                    'heading_cell_start'  => '<th>',
                    'heading_cell_end'    => '</th>','row_alt_start' =>'<tr class="tb-jd">','row_alt_end' =>'</tr>');
			$this->table->set_template($tmpl);
			$this->table->set_empty("&nbsp;");
			$this->table->set_heading('No','<h3>Product</h3>','<h3>Name</h3>','<h3>Descr</h3>','<h3>Detail_1</h3>','<h3>Detail_2</h3>','<h3>Detail_3</h3>','<h3>Detail_4</h3>','<h3>Detail_5</h3>','<h3>action</h3>');

			$acd = $this->Searchmodel->search_product2($product);
			$i =0;
			foreach($acd->result() as $ac12) {
				$this->table->add_row(++$i,$ac12->product,$ac12->name,$ac12->descr,$ac12->detail_1,$ac12->detail_2,$ac12->detail_3,$ac12->detail_4,$ac12->detail_5,anchor('master/product/update_products/'.$ac12->prod_id,'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;',array('class'=>'update')).''.
				anchor('master/product/delete_product/'.$ac12->prod_id,'delete',array('class'=>'delete2','onclick'=>"return confirm('Anda yakin akan menghapus data ini?')")));
			}
			
		}else if((($by2) != "") and (isset($by2) != "TickedID") and (($by2) != "DateRange") and (($by2) != "Severity") and (($by2) != "Comments") and (($by2) != "Product") and (($by2) == "Title")){
						
		}else {
			//set template table untuk efek selang-sling tiap bariS
			$tmpl = array('table_open' =>'<table border="0" cellpadding="0" cellspacing="0" width="880" id="table" class="sortable">', 'heading_row_start'   => '<thead><tr>',
                    'heading_row_end'     => '</tr></thead>',
                    'heading_cell_start'  => '<th>',
                    'heading_cell_end'    => '</th>','row_alt_start' =>'<tr class="tb-jd">','row_alt_end' =>'</tr>');
			$this->table->set_template($tmpl);
			$this->table->set_empty("&nbsp;");
			$this->table->set_heading('No','<h3>ticket_id</h3>','<h3>title</h3>','<h3>Open Date</h3>','<h3>Target Date</h3>','<h3>Close Date</h3>',
			'<h3>status</h3>','<h3>Level_o_Impact</h3>','<h3>Prob_o_Impact</h3>','<h3>Severity_Level</h3>','<h3>product</h3>');
		
		}
		}
		$this->data['table'] = $this->table->generate();
		//-------------------------------------------------------------------------------------------------------------------------
		$this->load->vars($this->data);
			$this->load->view('layout/head');
			$this->load->view('layout/body');
			$this->load->view('layout/slice-atas');
			$this->load->view('search/search_data');
			$this->load->view('layout/slice_bawah');
		

	}
	
	function advanced_search() {
		$this->data['title'] = 'Advanced Search';
		$this->data['h2_title'] = 'Advanced Search';
		$this->data['ticket'] = $this->Searchmodel->search_tickets ();
		$this->data['prod'] = $this->Searchmodel->search_product23();
		$this->load->vars($this->data);
			$this->load->view('layout/head');
			$this->load->view('layout/body');
			$this->load->view('layout/slice-atas');
			$this->load->view('search/advanc_search');
			$this->load->view('layout/slice_bawah');
	}
	 function show_advanced_search() {
	 	$this->data['titles'] = 'Advanced Search';
	 	$this->data['severity'] = $this->input->post('severity_level');
		$this->data['prod_id']	= $this->input->post('prod_id');
		$this->data['ticket_id'] = addslashes($this->input->post('ticket_id'));
		$this->data['date_time'] = $this->input->post('open_datetime');
		$this->data['title'] = $this->input->post('title');
		
		
		//$this->data['show'] =$this->Searchmodel->search_advanced($severity,$prod_id,$ticket_id,$date_time,$title);
		//$ql =mysql_query("select a.*,b.product,c.name from(ticket a,product b,user c) where a.prod_id = b.prod_id and a.user_id = c.user_id  and product ='$prod_id' and severity_level ='$severity' and (ticket_id like("%$ticket_id%") ||  open_datetime like("%$date_time%") || title like("%$title%"))");
		//$this->data['show'] = $ql;
		$this->load->vars($this->data);
			$this->load->view('layout/head');
			$this->load->view('layout/body');
			$this->load->view('layout/slice-atas');
			$this->load->view('search/show_advanced');
			$this->load->view('layout/slice_bawah');
		
		
	 	
	 }
	 function search_alls($id) {
	 	$this->data['search'] = $this->Searchmodel->search_alls($id);
		
		$this->load->vars($this->data);
		$this->load->view('layout/head');
		$this->load->view('layout/body');
		$this->load->view('layout/slice-atas');
		$this->load->view('search/search_alls');
		$this->load->view('layout/slice_bawah');
		
		
	 }
}
?>